<?php
include_once "../config/config.php";
include_once "../lib/pdodbmanager.php";
include_once "../lib/functions.php";
include_once "../lib/senitize.php";
$pdo_obj=new PDODBMNanager(HOST,DB,USERNAME,PASS);

//$_REQUEST['test_id']=3;
$selecttestresult=$pdo_obj->selectdata("select * from tests where id=".$_REQUEST['test_id']."");

$firstvalue=0;
$sameflag=1;
$selecttestquestionsettings=$pdo_obj->selectdata("select * from test_question_settings where test_id=".$_REQUEST['test_id']."");
for($i=0;$i<count($selecttestquestionsettings);$i++)
{
	if($i==0)
	{
		$firstvalue=$selecttestquestionsettings[$i]['marks_perquestion'];
	}
	else
	{
		if($selecttestquestionsettings[$i]['marks_perquestion']!=$firstvalue)
		{
			$sameflag=0;
		}
	}
	$arr_levels[$selecttestquestionsettings[$i]['difficulty_level_id']]=$selecttestquestionsettings[$i]['questions'];
	$arr_marks[$selecttestquestionsettings[$i]['difficulty_level_id']]=$selecttestquestionsettings[$i]['marks_perquestion'];
}
//print_r($arr_levels);
foreach($arr_levels as $keyDiffLevel=>$valQuestionCount)
{
	$fet_question_arr[$keyDiffLevel]=$pdo_obj->selectdata("select * from questions,test_questions where test_questions.test_id=".$_REQUEST['test_id']." and test_questions.question_id=questions.id  and  difficulty_level_id=$keyDiffLevel order by rand() limit $valQuestionCount");
}
//echo "<pre>";
//print_r($fet_question_arr);
//echo "</pre>";
?>
<style type="text/css">
table
{
    width:  100%;
    padding:10px;
    /*font-family: arialunicid0; /* freesans / times /  */
}
</style>
<page>
<br>
<div style="font-size: 45px; font-weight: bold;margin: auto;width:600px;position: relative;border:0px solid"><img src="../images/phone_support.jpg" width=""><br></div>
<br><br>
<div style="font-size: 22px; font-weight: bold;margin: auto;width:330px;position: relative;border:0px solid"><u><?php echo $selecttestresult[0]['test_name']; ?> TEST - SET <?php echo "T".$y; ?></u><br></div>
<br><br>
<span style="font-size: 22px;"> <span style=""> Name:</span> ________________________ &nbsp;&nbsp;<span style="">Contact No.</span> ________________</span>
<br><br><br>
<span style="">&nbsp;&nbsp;<font size="18px">Instructions:-</font></span>

<table  cellspacing="5" cellpadding="5" style="line-height:2;">
	<tr>
		<td >
			<?php echo nl2br(stripcslashes($selecttestresult[0]['guidelines'])); ?>
		</td>
	</tr>
</table>	

<div style="margin: auto;width:300px;position: relative;">-------------------------------------------------------------------</div><br>
<table cellspacing="5" cellpadding="5" style="font-size:15px;line-height:1.5;">

	<?php
	$sno_count=0;
	$array_sno=array("1"=>"A","2"=>"B","3"=>"C","4"=>"D","5"=>"E");
	foreach($arr_marks as $keyDiff=>$marks_per_question)
	{
		//echo $keyDiff;
		
		foreach($fet_question_arr[$keyDiff] as $key=>$valuearr)
		{
			$sno_count++;
			?>
			<tr>
				<td style="padding-right:5px;vertical-align:top;width:10px"><?php echo $sno_count; ?></td>
				<td style="width:650px"><?php echo $valuearr['question']; ?></td>
			</tr>
			<?php
			if($valuearr['question_image']!="")
			{
				$sizearr=getimagesize("../uploads/questionimages/".$valuearr['question_image']);

				?>
				
			<tr>
				<td></td>
				<td style="width:650px"><img src="<?php echo "../uploads/questionimages/".$valuearr['question_image']; ?>" <?php $height=$sizearr[1]; if($sizearr[1]>300){ $height=300; }else echo $height=$sizearr[1]; ?> style="height:<?php echo $height; ?>px">
				</td>
			</tr>
				<?php
			}
			for($n=1;$n<=$valuearr['no_of_choices'];$n++)
			{
			?>
			<tr>
				<td></td>
				<td style="padding-left:10px"><?php echo $array_sno[$n]; ?>. <?php echo $valuearr['option'.$n]; ?></td>
			</tr>
			<?php
			}
			?>
			<tr>
				<td colspan="2">&nbsp;</td>
			</tr>
			<?php
		}
	}
	?>

</table>
</page>
<page>
<br>
<div style="font-size: 20px; font-weight: bold;margin: auto;width: 325px;position: relative;"><u>ANSWER SHEET - SET <?php echo "T".$y; ?></u><br></div>
<br>
<table cellspacing="5" cellpadding="5" >

	<?php
	$sno_count=0;
	
	foreach($arr_marks as $keyDiff=>$marks_per_question)
	{
		//echo $keyDiff;
		
		foreach($fet_question_arr[$keyDiff] as $key=>$valuearr)
		{
			$sno_count++;
			
			?>
			<tr>
				<td style="width:10px;padding-right:5px;vertical-align:top"><?php echo $sno_count; ?></td>
				<td style="width:650px"><?php echo $valuearr['question']; ?></td>
				
			</tr>
			<tr>
				<td>Ans:</td>
				<td><?php 
						$display_answer="";
						if(stristr($valuearr['answer'],","))
						{
							$expolde_ans=explode(",",$valuearr['answer']);
							for($s=0;$s<count($expolde_ans);$s++)
							{
								$display_answer.=$array_sno[$expolde_ans[$s]]." (".$valuearr['option'.$expolde_ans[$s]]."), ";
							}
							$display_answer=substr($display_answer,0,strlen($display_answer)-2);
						}
						else
						{
							$display_answer= $array_sno[$valuearr['answer']]." (".$valuearr['option'.$valuearr['answer']].")";
						}
						
						echo $display_answer;
					 ?></td>
				
			</tr>
			
			
			<tr>
				<td colspan="2">&nbsp;</td>
				
			</tr>
			<?php
		}
	}
	?>
 <!--   
<?php
    for ($k=0; $k<50; $k++) {
?>
    <tr>
        <th><?php echo $k; ?></th>
        <td>test de texte assez long pour engendrer des retours à la ligne automatique...</td>
        <td>test de texte assez long pour engendrer des retours à la ligne automatique...</td>
        <td style="width:50px"> marks</td>
    </tr>
<?php
    }
?>
    -->
</table>
</page>